(function($) {
	$(':text[rel~=bankname], select[rel~=bankname]').each(function(index) {
		var self = $(this), id = self.attr('id');
		if(self.data('country-field') != ''){
			var country_field = self.parents('form').find(':input[name="' + self.data('country-field') + '"]'), country = country_field.val(), url = self.data('url'), country_field_id = country_field.attr('id');
			if(country != '' && url != ''){
				self.prop('disabled', true);
				$.get(url, {'country': country}, function(data) {
					if(data != ''){
						self.replaceWith(data);
					}
				})
				.always(function() {
					self.prop('disabled', false);
		  		});
			}

			$('#' + country_field_id).live("change", function(e) {
				e.preventDefault();
				var self = $('#' + id), url = self.data('url'), country = $(this).val();
				if(country != '' && url != ''){
					self.prop('disabled', true);
					$.get(url, {'country': country}, function(data) {
						if(data != ''){
							self.replaceWith(data);
						}
					})
					.always(function() {
						self.prop('disabled', false);
			  		});
				}
			});
		}
	});
})(jQuery);